#ifndef ___CHANNEL_HPP___
#define ___CHANNEL_HPP___

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <unistd.h>

// 先描述
class Channel
{
public:
    Channel(int wfd, pid_t who)
        : _wfd(wfd),
          _who(who)
    {
        // Channle-3-1234
        _name = "Channel-" + std::to_string(_wfd) + "-" + std::to_string(who);
    }

    std::string Name()
    {
        return _name;
    }

    void Send(int cmd)
    {
        ::write(_wfd, &cmd, sizeof(cmd));
    }

    void Close()
    {
        ::close(_wfd);
    }

    pid_t Id()
    {
        return _who;
    }

    ~Channel()
    {
    }

private:
    int _wfd;
    std::string _name;
    pid_t _who;
};

#endif